/**
 * createRouter 这个为创建路由的方法
 * createWebHashHistory 这个就是vue2中路由的模式，
 *                      这里的是hash模式，这个还可以是createWebHistory等
 * RouteRecordRaw 这个为要添加的路由记录，也可以说是routes的ts类型
 */
import { createRouter, createWebHashHistory, RouteRecordRaw } from 'vue-router';
// 路由记录，这个跟vue2中用法一致，就不做过多解释了
const routes: Array<RouteRecordRaw> = [
  {
    path: '/',
    name: 'index',
    meta: {
      title: '首页',
    },
    component: () => import("@/views/index.vue"),
    children: [
      {
        path: '/zhuanpan',
        name: 'zhuanpan',
        meta: {
          title: '转盘抽奖',
        },
        component: () => import("@/views/page/zhuanpan.vue"),
      },
      {
        path: '/jiugongge',
        name: 'jiugongge',
        meta: {
          title: '九宫格抽奖',
        },
        component: () => import("@/views/page/jiugongge.vue"),
      },
      {
        path: '/paizhao',
        name: 'paizhao',
        meta: {
          title: '九宫格抽奖',
        },
        component: () => import("@/views/page/paizhao.vue"),
      },
      {
        path: '/three3D',
        name: 'three3D',
        meta: {
          title: '九宫格抽奖',
        },
        component: () => import("@/views/page/three3D.vue"),
      },
    ]
    
  }
];

const router = createRouter({
  history: createWebHashHistory(),
  routes
});
router.beforeEach((to, from, next) => {
  console.log(from);  
  document.title = to.meta.title ? `${document.title}—${to.meta.title}` : document.title;
  next()
})
export default router;